//
//  MPStore.h
//  MissPaparazzi
//
//  Created by Alexey Aleshkov on 02.09.12.
//  Copyright (c) 2012 DzeTech. All rights reserved.
//


#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <StoreKit/StoreKit.h>
#import "MPDownloader.h"
#import "AFNetworking.h"
#import "MPEpisode.h"
#import "Reachability.h"


typedef void(^MPStoreSuccessBlock)(void);
typedef void(^MPStoreFailureBlock)(NSError *);


@interface MPStore : NSObject
{
	NSManagedObjectContext *_managedObjectContextStore;
	NSPersistentStore *_persistentStoreStore;
	NSPersistentStoreCoordinator *_persistentStoreCoordinatorStore;
	NSManagedObjectModel *_managedObjectModelStore;

	MPDownloader *_downloader;
	
	AFHTTPClient *_client;
	
	Reachability *_reachability;

	NSString *_archivesPath;
	NSString *_episodesPath;
}

+ (MPStore *)sharedInstance;

@property (nonatomic, readonly) NSManagedObjectContext *managedObjectContext;

- (void)updateWithSuccessBlock:(MPStoreSuccessBlock)successBlock failureBlock:(MPStoreFailureBlock)failureBlock;

- (void)restorePurchasesWithSuccessBlock:(MPStoreSuccessBlock)successBlock failureBlock:(MPStoreFailureBlock)failureBlock;

- (void)purchaseAllItemsWithSuccessBlock:(MPStoreSuccessBlock)successBlock failureBlock:(MPStoreFailureBlock)failureBlock;
- (void)purchaseItem:(MPEpisode *)item successBlock:(MPStoreSuccessBlock)successBlock failureBlock:(MPStoreFailureBlock)failureBlock;
- (void)downloadItem:(MPEpisode *)item successBlock:(MPStoreSuccessBlock)successBlock failureBlock:(MPStoreFailureBlock)failureBlock;
- (void)cancelDownloadingItem:(MPEpisode *)item;
- (void)removeItem:(MPEpisode *)item;

- (BOOL)isDownloaded:(MPEpisode *)item;

- (NSString *)imagePathForItem:(MPEpisode *)item;
- (NSString *)videoPathForItem:(MPEpisode *)item;
- (BOOL)isImageExists:(MPEpisode *)item;
- (BOOL)isVideoExists:(MPEpisode *)item;

- (NSString *)buyAllProductPrice;

- (void)pauseAllDownloads;
- (void)resumeAllDownloads;

@end
